package com.nf.health.app.main_intervention.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.nf.health.app.R;
import com.nf.health.app.main_intervention.bean.MedicinedDietBean;
import com.nf.health.app.utils.ImageLoaderUtils;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by he_pan on 2016/11/24.
 * The only genius that is worth anything is the genius for hard work
 *
 * @author he_pan
 * @Description 食物小图片和所需要的重量
 */

public class GvFoodImageAdapter extends BaseAdapter {
    private Context ctx;
    List<MedicinedDietBean.FoodlistBean.FooddepotBean> mFoodList;

    public GvFoodImageAdapter(Context ctx, List<MedicinedDietBean.FoodlistBean.FooddepotBean> mFoodList) {
        this.ctx = ctx;
        this.mFoodList = mFoodList;

    }

    @Override
    public int getCount() {
        return mFoodList.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = View.inflate(ctx, R.layout.item_gv_food_image, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
//        Glide.with(ctx).load(mFoodList.get(0).getFooddepot().get(0).getPicture()).
//                transform(new GlideRoundTransform(ctx)).
//                placeholder(R.drawable.default_square_image).into(holder.ivFoodImage); //有时候加载高度不对??why
        ImageLoaderUtils.getinstance(ctx).
                getRoundedImage(holder.ivFoodImage, mFoodList.get(position).getPicture(), R.drawable.default_square_image, 20);

        holder.tvFoodName.setText(mFoodList.get(position).getName());
        return convertView;
    }

    class ViewHolder {
        @Bind(R.id.iv_food_image)
        ImageView ivFoodImage;
        @Bind(R.id.tv_food_name)
        TextView tvFoodName;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
